﻿@{
    ViewBag.Title = "Purchase_View";
    Layout = "~/Views/Users/Index.cshtml";
}
<link href="~/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/js/jquery.min.js"></script>
<script src="~/js/bootstrap.min.js"></script>
<h2>进货</h2>

<table>
    <tr>
        <td>进货单号：</td>
        <td><input id="Invoice_number" type="text"  /><span style="color:red;" id="invoiceerror"></span></td>
    </tr>
    <tr>
        <td>供货商：</td>
        <td><input id="Supplier" type="text" /><span style="color:red;" id="superror"></span></td>
    </tr>
    <tr>
        <td><input  type="button" value="添加商品"  onclick="return location.href = '/Purchase/PurchaseGeneral_View';"/></td>
        <td></td>
    </tr>
</table>

<table  border="1" width="500">
    <tr>
        <th>商品编号</th>
        <th>商品名称</th>
        <th>数量</th>
        <th>单价</th>
    </tr>
    @{
        foreach (var item in Model)
        {
            <tr>
                <td>@item.commodityID</td>
                <td>@item.FlowersName</td>
                <td>@item.PurchaseNumber</td>
                <td>@item.PurchasePrice</td>
            </tr>
        }
        
        var sum = 0;
        foreach(var ss in Model)
        {
            sum += ss.PurchaseNumber*ss.PurchasePrice;
        }
    }
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>合计: @sum 元</td>
    </tr>
</table>
<table width="500">
    <tr>
        <td width="350"></td>
        <td></td>
        <td></td>
        <td><input  type="button" value="确认进货" style="width:176px;"  onclick="addall()"/></td>
    </tr>
</table>

<script>
    function addall()
    {
        if ($("#Invoice_number").val() == "" &&  $("#Supplier").val() == "")
        {
            $("#invoiceerror").html("请填写此信息！");
            $("#superror").html("请填写此信息！");
        }
        else if($("#Invoice_number").val() == "")
        {
            $("#invoiceerror").html("请填写此信息！");
            $("#superror").html("");
        }
        else if($("#Supplier").val() == "")
        {
            $("#superror").html("请填写此信息！");
            $("#invoiceerror").html("");
        }
        else
        {
            var Invoice_number = $("#Invoice_number").val();
            var Supplier = $("#Supplier").val();

            $.ajax({
                type: "post",
                url: "/Purchase/PurchaseOrderAdd",
                data:
                    {
                        Invoice_number: Invoice_number,
                        Supplier: Supplier
                    },
                success: function (result) {
                    if (result > 0) {
                        alert("进货成功！！");
                        location.href = '/Purchase/Purchase_View';
                    }
                    else {
                        alert("进货失败！！");
                        location.href = '/Purchase/Purchase_View';
                    }
                }
            })
        }

    }
</script>


